package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Cables;
import com.ruoyi.system.service.ICablesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 光缆表Controller
 * 
 * @author ruoyi
 * @date 2025-02-13
 */
@RestController
@RequestMapping("/system/cables")
public class CablesController extends BaseController
{
    @Autowired
    private ICablesService cablesService;

    /**
     * 查询光缆表列表
     */
    @PreAuthorize("@ss.hasPermi('system:cables:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cables cables)
    {
        startPage();
        List<Cables> list = cablesService.selectCablesList(cables);
        return getDataTable(list);
    }

    /**
     * 导出光缆表列表
     */
    @PreAuthorize("@ss.hasPermi('system:cables:export')")
    @Log(title = "光缆表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cables cables)
    {
        List<Cables> list = cablesService.selectCablesList(cables);
        ExcelUtil<Cables> util = new ExcelUtil<Cables>(Cables.class);
        util.exportExcel(response, list, "光缆表数据");
    }

    /**
     * 获取光缆表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cables:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cablesService.selectCablesById(id));
    }
/**
 * 新增光缆表
 */
@PreAuthorize("@ss.hasPermi('system:cables:add')")
@Log(title = "光缆表", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody Cables cables) {
    int result = cablesService.insertCables(cables);
    if (result > 0) {
        // 返回插入后的Cables对象
        return AjaxResult.success(cables);
    } else {
        return AjaxResult.error("新增失败");
    }
}

    /**
     * 修改光缆表
     */
    @PreAuthorize("@ss.hasPermi('system:cables:edit')")
    @Log(title = "光缆表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cables cables)
    {
        return toAjax(cablesService.updateCables(cables));
    }

    /**
     * 删除光缆表
     */
    @PreAuthorize("@ss.hasPermi('system:cables:remove')")
    @Log(title = "光缆表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cablesService.deleteCablesByIds(ids));
    }
}
